﻿#include "KBEMain.h"
#include "KBundle.h"
#include "client/KAccount.h"
#include "KBEApplication.h"
#include "KBEGameSocket.h"
#include "KMessage.h"
#include "helper/log.h"

using namespace KBEngineClient;

void testKBE()
{
    KBEGameSocket &game_sock = KBEGameSocket::getInstance();
    std::string s_ip = "23.239.157.86";
    s_ip = "192.168.10.101";
    bool c_ok = game_sock.connectionServer(s_ip.c_str(), 10013);
	if (!c_ok)
		xpy::logger::error("net not connected.");

    //KMessage::bindmessage();
	KBE_init();
    //send ["Loginapp_importClientMessages"]);
    KBundle *bundle = new KBundle();

    KNetworkInterface *network = new KNetworkInterface();

    bundle->newmessage(*KMessage::messages["Loginapp_importClientMessages"]);
    bundle->send(*network);

    //next we should recv huge client methods....

    /*KBEngineClient::Message msg;
    msg.setOpcode(100);
    game_sock.sendMessage(msg);*/
    //TODO works like a clientapp. say hello. send importEntiityDef message.
    //pack1:
    //Message.messages["Loginapp_importClientMessages"] = new Message(5, "importClientMessages", 0, 0, new List<Byte>(), null);
    //bundle.newMessage(Message.messages["Loginapp_importClientMessages"]);
    //bundle.send(networkInterface_);
    //bundle get stream from message.
    //scene->addChild(game_sock ,19999,19999);
}

void ccTouchesBegan()
{
    KAccount *account = (KAccount *)KBEngineClient::ClientApp::getInstance().pPlayer();
    account->sendMsg(" cocos2dx coming! ");
}
